﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Small.Util.Reflection
{
   public class DefinationProperties
    {


       /// <summary>
       /// 获取到类的名称
       /// </summary>
       /// <typeparam name="T"></typeparam>
       /// <returns></returns>
       public static List<String> GetName<T>(T t) 
       {
           
           
           List<String> list = new List<string>();

           foreach (var item in t.GetType().GetProperties())
           {
               list.Add(item.Name);
           }

           return list;
       }

       /// <summary>
       /// 获取类的名称与值
       /// </summary>
       /// <typeparam name="T"></typeparam>
       /// <returns></returns>
       public static Dictionary<string, string> GetProperties<T>(T t)
       {
          Dictionary<string,string> dictionary = new Dictionary<string,string>();

           foreach (PropertyInfo item in t.GetType().GetProperties())
           {
               dictionary.Add(item.Name, Convert.ToString(item.GetValue(t,null)));
           }

           return dictionary;
        
       }
    }
}
